package com.benbi.shequapi.controller;


import com.benbi.shequapi.service.NewsService;
import com.benbi.shequapi.utils.Result;
import org.apache.ibatis.annotations.Param;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

@RestController
@RequestMapping("/news")
public class NewsController {
    @Resource
    NewsService newsService;

    @RequestMapping("/getNewsList")
    public Result getNewsList() {
        return newsService.getNewsList();
    }

    @RequestMapping("/getNews")
    public Result getNews(@RequestParam("news_id") int news_id)
    {
        return newsService.getNewsByNewsid(news_id);
    }

    @RequestMapping("/deleteNews")
    public Result deleteNews(@RequestParam("news_id") int news_id){
        return newsService.deleteNews(news_id);
    }

    @RequestMapping("/addNews")
    public Result addNews(
            @RequestParam("a_pid")int a_pid,
            @RequestParam("top")int top,
            @RequestParam("title")String title,
            @RequestParam("content")String content){
        return newsService.newNews(a_pid,top,title,content);
    }

//    @RequestMapping("/test")
//    public Result test(@RequestParam("date") @DateTimeFormat(pattern = "yyyy-MM-dd hh:mm:ss") Date date){
//        Person p = new Person();
//        p.setBirthdate(date);
//        System.out.println(date);
//        System.out.println(p.getBirthdate());
//        return new Result();
//    }

}
